<template>
  <div id="centerRight1">
    <div class="bg-color-black">
      <div class="d-flex pt-2 pl-2">
        <span>
          <icon name="chart-line" class="text-icon"></icon>
        </span>
        <div class="d-flex">
          <span class="fs-xl text mx-2">订单实况</span>
        </div>
      </div>
      <div class="d-flex jc-center body-box">
        <dv-scroll-board v-if="visible" class="dv-scr-board" :config="config" />
      </div>
    </div>
  </div>
</template>

<script>
import { dateFormat } from "@/util/date";
import { lastTicketTen } from "@/api/statics/dataview";

export default {
  props: {
    shop: {
      type: String,
      default: () => ''
    }
  },
  data() {
    return {
      config: {
        header: ['ID', '支出', '收入', '利润'],
        data: [],
        rowNum: 7, //表格行数
        headerHeight: 35,
        headerBGC: '#0f1325', //表头
        oddRowBGC: '#0f1325', //奇数行
        evenRowBGC: '#171c33', //偶数行
        index: true,
        columnWidth: [20, 120, 60, 60, 60],
        align: ['center']
      },
      visible: true
    }
  },
  watch: {
    shop() {
      this.getList()
    }
  },
  mounted() {
    this.changeTiming()
    this.getList()
  },
  methods: {
    getList() {
      const start = new Date()
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 180);
      const monthParams = {
        startTime: dateFormat(start, 'yyyy-MM-dd 00:00:00'),
        endTime: dateFormat(new Date(), 'yyyy-MM-dd 23:59:59')
      }
      const params = {}
      if (this.shop && this.shop !== '') {
        params.shopName = this.shop
      }
      this.visible = false
      lastTicketTen(params).then(res => {
        const data = res.data.data
        const list = []
        data.map(item => {
          list.push([item.id, item.cost, item.amount, item.profit])
        })
        this.$set(this.config, 'data', list)
        this.$forceUpdate()
        this.visible = true
      })
    },
    changeTiming() {
      setInterval(() => {
        this.getList()
      }, 30000)
    }
  }
}
</script>

<style lang="scss" scoped>
$box-height: 410px;
$box-width: 340px;
#centerRight1 {
  padding: 16px;
  padding-top: 20px;
  height: $box-height;
  width: $box-width;
  border-radius: 5px;
  .bg-color-black {
    height: $box-height - 30px;
    border-radius: 10px;
  }
  .text {
    color: #c3cbde;
  }
  .body-box {
    border-radius: 10px;
    overflow: hidden;
    .dv-scr-board {
      width: 310px;
      height: 340px;
    }
  }
}
</style>
